//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "StrippedOptionletBase.h"
using namespace Cephei::QL::Termstructures::Volatility::Optionlet;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (boost::shared_ptr<QuantLib::StrippedOptionletBase>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStrippedOptionletBase = NULL;
#endif
	_ppStrippedOptionletBase = &childNative;
    
}
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (QuantLib::StrippedOptionletBase& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phStrippedOptionletBase = NULL;
#endif
	_ppStrippedOptionletBase = new boost::shared_ptr<QuantLib::StrippedOptionletBase> (&childNative);
    
    _StrippedOptionletBaseOwner = owner;
    
}

Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (CStrippedOptionletBase^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStrippedOptionletBase = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppStrippedOptionletBase = new boost::shared_ptr<QuantLib::StrippedOptionletBase> (copy->GetShared());
        
    }
}
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStrippedOptionletBase = NULL;
#endif
	if (!t->IsSubclassOf(CStrippedOptionletBase::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (QuantLib::Handle<QuantLib::StrippedOptionletBase>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phStrippedOptionletBase = &childNative;
	_ppStrippedOptionletBase = &static_cast<boost::shared_ptr<QuantLib::StrippedOptionletBase>>(childNative.currentLink());
    
    _StrippedOptionletBaseOwner = owner;
}
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (QuantLib::Handle<QuantLib::StrippedOptionletBase> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phStrippedOptionletBase = &childNative;
	_ppStrippedOptionletBase = &static_cast<boost::shared_ptr<QuantLib::StrippedOptionletBase>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::CStrippedOptionletBase (QuantLib::StrippedOptionletBase childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStrippedOptionletBase = NULL;
#endif
	_ppStrippedOptionletBase = new boost::shared_ptr<QuantLib::StrippedOptionletBase> (new QuantLib::StrippedOptionletBase (childNative));
    
}
#endif

Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::~CStrippedOptionletBase ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppStrippedOptionletBase != NULL)
    {
	    delete _ppStrippedOptionletBase;
        _ppStrippedOptionletBase = NULL;
    }
}
Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::!CStrippedOptionletBase ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppStrippedOptionletBase != NULL)
    {
	    delete _ppStrippedOptionletBase;
    }
}
QuantLib::StrippedOptionletBase& Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::GetReference ()
{
    if (_ppStrippedOptionletBase == NULL) throw gcnew NativeNullException ();
	return **_ppStrippedOptionletBase;
}
boost::shared_ptr<QuantLib::StrippedOptionletBase>& Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::GetShared ()
{
    if (_ppStrippedOptionletBase == NULL) throw gcnew NativeNullException ();
	return *_ppStrippedOptionletBase;
}
QuantLib::StrippedOptionletBase* Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::GetPointer ()
{
    if (_ppStrippedOptionletBase == NULL) throw gcnew NativeNullException ();
	return &**_ppStrippedOptionletBase;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::StrippedOptionletBase>& Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::GetHandle ()
{
	if (_phStrippedOptionletBase == NULL)
	{
		_phStrippedOptionletBase = new Handle<QuantLib::StrippedOptionletBase> (*_ppStrippedOptionletBase);
	}
	return *_phStrippedOptionletBase;
}
#endif
bool Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::HasNative () 
{
	return (_ppStrippedOptionletBase != NULL);
}

Cephei::IVector<Double>^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::AtmOptionletRates::get ()
{
    try
    {
    	std::vector<QuantLib::Rate>& _rv = (std::vector<QuantLib::Rate>&)(*_ppStrippedOptionletBase)->atmOptionletRates ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::BusinessDayConvention::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppStrippedOptionletBase)->businessDayConvention ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ICalendar^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::Calendar::get ()
{
    try
    {
    	QuantLib::Calendar _rv = (QuantLib::Calendar)(*_ppStrippedOptionletBase)->calendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = gcnew Cephei::QL::Times::CCalendar (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::DayCounter::get ()
{
    try
    {
    	QuantLib::DayCounter _rv = (QuantLib::DayCounter)(*_ppStrippedOptionletBase)->dayCounter ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = gcnew Cephei::QL::Times::CDayCounter (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<DateTime>^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::OptionletFixingDates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppStrippedOptionletBase)->optionletFixingDates ( );   
        Cephei::IVector<DateTime>^ _nrv = gcnew CoVector<DateTime> (gcnew CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::OptionletFixingTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppStrippedOptionletBase)->optionletFixingTimes ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::OptionletMaturities::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppStrippedOptionletBase)->optionletMaturities ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::OptionletStrikes (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	std::vector<QuantLib::Rate>& _rv = (std::vector<QuantLib::Rate>&)(*_ppStrippedOptionletBase)->optionletStrikes ( _i );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::OptionletVolatilities (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppStrippedOptionletBase)->optionletVolatilities ( _i );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Termstructures::Volatility::Optionlet::CStrippedOptionletBase::SettlementDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppStrippedOptionletBase)->settlementDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

